package com.stu.action;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.stu.model.Stu;
import com.stu.service.StuService;
import com.stu.service.impl.StuServiceImpl;

/**
 * Servlet implementation class StuAction
 */
@WebServlet("/StuAction")
public class StuAction extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
  
    public StuAction() {
        super();
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		Stu stu=new Stu();
		stu.setLoginname(request.getParameter("loginname"));
		stu.setPassword(request.getParameter("password"));
		stu.setSex(request.getParameter("sex"));
		StuService service=StuServiceImpl.getStuServiceImpl();
		if(service.save(stu)) {
			request.getRequestDispatcher("StuViewAction")
			.forward(request, response);
		}else {
			System.out.println("新增失败！");
		}
	}
}
